﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeavenBAL;
using FortuneHeaven.Admin.Common;
using System.Globalization;

namespace FortuneHeaven.Admin.Pages.Statistic
{
    public partial class NetpayStatistic : FortuneHeaven.Admin.Common.PageBase
    {
        public override string PageID
        {
            get { return "F64"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeptName.Text = "网银支付统计";
            this.usPager.PagerChanged += new Admin.Controls.TxtPagination.PagerChangeHandler(usPager_PagerChanged);
            if (!this.IsPostBack)
            {
                this.drpPagerSize.Items.Clear();
                this.drpPagerSize.Items.Add(new ListItem("每页10行", "10"));
                this.drpPagerSize.Items.Add(new ListItem("每页20行", "20"));
                this.drpPagerSize.Items.Add(new ListItem("每页50行", "50"));



                if (!string.IsNullOrEmpty(Request["pagesize"]))
                {
                    this.drpPagerSize.SelectedIndex = int.Parse(Request["pagesize"]);
                }
                else
                {
                    this.drpPagerSize.SelectedValue = "10";
                }

                //this.lvNews.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lvNews_ItemCommand);
            }
        }
        private void usPager_PagerChanged(object sender, int currentpage)
        {
            Refresh();
        }

        public void Refresh()
        {
            NetpayStaBO giftorder = new NetpayStaBO();
            DateTime start = DateTime.Now;
            DateTime end = DateTime.Now;
            DateTime.TryParse(this.txtBegin.Text,out start);
            DateTime.TryParse(this.txtEnd.Text, out end);
            int isMonth = 1;
            if (this.drpOrderType.SelectedValue.Trim() == "1")
            {
                isMonth = 1;

            }
            else
            {
                isMonth = 0;
            }
            lvNews.DataSource = giftorder.GetUserStatistic(this.usPager.CurrentPageIndex, int.Parse(this.drpPagerSize.SelectedValue), start, end, isMonth);
            lvNews.DataBind();
        }

        protected void drpPagerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList()
        {
            ResetList(1);
        }

        public void SearchValue(object sender, EventArgs e)
        {
            ResetList();
        }

        public string GetFormatValue(object value)
        {
            DateTime date = (DateTime)value;
            string ret = "";
            if (this.drpOrderType.SelectedValue.Trim() == "1")
            {
                ret = date.ToString("yyyy/MM");
            }
            else
            {
                ret = date.ToString("yyyy/MM/dd");
            }
            return ret;
        }

        public void ResetList(int current)
        {
            NetpayStaBO giftorder = new NetpayStaBO();
            DateTime start = DateTime.Now;
            DateTime end = DateTime.Now;
           
            DateTime.TryParse(this.txtBegin.Text, out start);
            DateTime.TryParse(this.txtEnd.Text,  out end);
            int isMonth = 1;
            if (this.drpOrderType.SelectedValue.Trim() == "1")
            {
                isMonth = 1;

            }
            else
            {
                isMonth = 0;
            }
            this.usPager.RecordCount = giftorder.GetTotalSize(start, end, isMonth);
            this.usPager.PageSize = int.Parse(this.drpPagerSize.SelectedValue);
            this.usPager.Initial();
            this.usPager.CurrentPageIndex = 1;
        }
    }
}